﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Helper.cs" company="ScRePt">
//   Copyright © ScRePt 2010 - 2012
// </copyright>
// <summary>
//   The helper.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace MP3D.Helper
{
    #region Using Directives

    using System.IO;
    using System.Reflection;

    using MediaPortal.Configuration;
    using MediaPortal.GUI.Library;

    #endregion

    /// <summary>
    /// The helper.
    /// </summary>
    public static class Helper
    {
        #region Constants and Fields

        /// <summary>
        /// The plugin author.
        /// </summary>
        public const string PluginAuthor = "ScRePt";

        /// <summary>
        /// The plugin description.
        /// </summary>
        public const string PluginDescription = "Render 3D via MediaPortal!";

        /// <summary>
        /// The plugin name.
        /// </summary>
        public const string PluginName = "MP3D";

        /// <summary>
        /// The plugin version.
        /// </summary>
        public const string PluginVersion = "1.4.0";

        #endregion

        #region Constructors and Destructors

        /// <summary>
        /// Initializes static members of the <see cref="Helper"/> class.
        /// </summary>
        static Helper()
        {
            SkinPathXml = GUIGraphicsContext.Skin + @"\";
            SkinPathMedia = GUIGraphicsContext.Skin + @"\Media\" + PluginName + @"\";
            SkinFileOsd = SkinPathXml + PluginName + "_OSD.xml";
            ConfigPath = Config.GetFolder(Config.Dir.Config) + @"\";
            ConfigFile = ConfigPath + PluginName + ".xml";

            if (!Directory.Exists(SkinPathMedia))
            {
                Directory.CreateDirectory(SkinPathMedia);
            }
        }

        #endregion

        #region Enums

        /// <summary>
        /// The plugin window Ids.
        /// </summary>
        public enum PluginWindowIds
        {
            /// <summary>
            /// The main window id.
            /// </summary>
            WindowIdOsd = 298375, 
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets ConfigFile.
        /// </summary>
        public static string ConfigFile { get; set; }

        /// <summary>
        /// Gets or sets ConfigPath.
        /// </summary>
        public static string ConfigPath { get; set; }

        /// <summary>
        /// The OSD skin file.
        /// </summary>
        public static string SkinFileOsd { get; set; }

        /// <summary>
        /// The media skin path.
        /// </summary>
        public static string SkinPathMedia { get; set; }

        /// <summary>
        /// The xml skin path.
        /// </summary>
        public static string SkinPathXml { get; set; }

        #endregion

        #region Public Methods

        /// <summary>
        /// The save resource to filename.
        /// </summary>
        /// <param name="filename">
        /// The filename.
        /// </param>
        /// <param name="resourceName">
        /// The resource name.
        /// </param>
        public static void SaveResourceToFilename(string filename, string resourceName)
        {
            using (Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
            {
                if (s == null)
                {
                    return;
                }

                using (FileStream fs = new FileStream(filename, FileMode.Create))
                {
                    using (BinaryReader reader = new BinaryReader(s))
                    {
                        using (BinaryWriter writer = new BinaryWriter(fs))
                        {
                            byte[] buffer = new byte[s.Length];
                            reader.Read(buffer, 0, buffer.Length);
                            writer.Write(buffer);
                        }
                    }
                }
            }
        }

        #endregion
    }
}